import {
  Controller,
  Post,
  Body,
  UseInterceptors
} from "@nestjs/common";
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { HomeService } from './home.service';
import {AccessTimeSlotDto} from './dto/index';
import { RedisInstance } from '@/common/redis';
import {LoggingInterceptor} from "@/common/interceptor/logging.interceptor";
import { operationTypeEnum } from '@/common/enum';

@ApiTags("后台首页")
@Controller("home")
export class HomeController {

  private redis:RedisInstance
  constructor(private readonly homeService:HomeService) {
    this.redis = new RedisInstance("user")
  }

  @Post("/accessStatistics")
  @ApiOperation({description:"后台访问人数总数"})
  @UseInterceptors(new LoggingInterceptor({data:"后台访问人数总数",logType:"operationLog",operationType:operationTypeEnum.other}))
  accessStatistics() {
    return this.homeService.accessStatistics();
  }
  @Post("/accessTimeSlot")
  @ApiOperation({description:"访问人数时间段"})
  @UseInterceptors(new LoggingInterceptor({data:"访问人数时间段",logType:"operationLog",operationType:operationTypeEnum.other}))
  accessTimeSlot(@Body() accessTimeSlotDto: AccessTimeSlotDto) {
    let dataRangeArr = JSON.parse(accessTimeSlotDto.dateRangeArr)
    return this.homeService.accessTimeSlot(dataRangeArr);
  }
  @Post("/artStatistics")
  @ApiOperation({description:"文章总数"})
  @UseInterceptors(new LoggingInterceptor({data:"文章总数",logType:"operationLog",operationType:operationTypeEnum.other}))
  artStatistics() {
    return this.homeService.artStatistics();
  }
}
